var loginObj = {
	tryLogin : function (userType) {
		var userid   = $F('userid');
		var password = $F('password');
		var params = 'handler=tryLogin&userid='+userid+'&password='+password+'&userType='+userType;
	
		var ajaxResults = new Ajax.Request('ajaxDirector.php', {
			method: 'POST',
			parameters: params,	
			onSuccess: function(transport) {
				loginObj.returnTryLogin(transport.responseText);
			},
			onFailure: function() {
				alert('Oops!');
			}		
		});
	},
	returnTryLogin : function (string) {
		var loginArray = string.split('|');
		var loginError   = loginArray[0];
		var loginMessage = loginArray[1];
		if ($('contactID')) {
			var contactID    = $F('contactID');
		}
		if ($('ptiResourceShare')) {
			var ptiResourceShare = 1;
		}
		
		if (contactID>0) {
			var redirectLink = 'contactForm.php?contactID='+contactID;
		} else if (ptiResourceShare == 1) {
			//var redirectLink = 'ptishare/index.php';
			var redirectLink = 'http://www.childdisabilityconnection.org/ptishare/index.php';
		} else {
			var redirectLink = 'http://www.childdisabilityconnection.org/admin/index.php';
		}
		
		if (loginError == '0') {
			$('errorMessage').className  = '';
			$('errorMessage').innerHTML  = '';
			window.location = redirectLink;
		} else {
			$('errorMessage').className  = 'errorMessageBig';
			$('errorMessage').innerHTML = loginMessage;
		}
	}
}

var findPasswordObj = {
	findPassword : function() {
		var email = $F('email');
		if (email == '') {
			$('errorMessage').className  = 'errorMessageBig';
			$('errorMessage').innerHTML = 'You must enter an email address.';
		} else {
			var params = 'handler=findPassword&email='+email;
	
			var ajaxResults = new Ajax.Request('ajaxDirector.php', {
			method: 'POST',
			parameters: params,	
			onSuccess: function(transport) {
				findPasswordObj.returnFindPassword(transport.responseText);
			},
			onFailure: function() {
				alert('Oops!');
			}		
		});
		}
	},
	returnFindPassword : function(status) {
		if (status == 'error') {
			$('errorMessage').className  = 'errorMessageBig';
			$('errorMessage').innerHTML = 'The email address you entered cannot be found.';
		} else {
			$('errorMessage').className  = 'successMessageBig';
			$('errorMessage').innerHTML = 'Your login information has been sent to your email address.';
			$('formLogin').style.display = '';
			$('formFindPassword').style.display = 'none';
		}
	},
	openFindPasswordForm : function() {
		$('errorMessage').className  = '';
		$('errorMessage').innerHTML = '';
		$('formLogin').style.display = 'none';
		$('formFindPassword').style.display = '';		
	},
	cancel : function() {
		$('errorMessage').className  = '';
		$('errorMessage').innerHTML = '';
		$('formLogin').style.display = '';
		$('formFindPassword').style.display = 'none';
	}
}

var viewTabContent = {
	content0Load : function() {
		$('userid').focus();
	}
}